<template>
	<div class="fillcontain">
		<el-row style="height: 100%;">
			<el-col :span="4" style="min-height: 100%; background-color:white;height:100%">
				<el-menu :default-active="defaultActive" style="min-height: 100%;" router>
					<el-menu-item index="manage"><i class="el-icon-menu"></i>首页</el-menu-item>
					<el-submenu index="2">
						<template slot="title"><i class="el-icon-document"></i>数据管理
</template>
						<el-menu-item index="userList">用户列表</el-menu-item>
						<el-menu-item index="message">消息列表</el-menu-item>
					</el-submenu>
					<el-submenu index="3">
<template slot="title">
	<i class="el-icon-plus"></i>排课管理
</template>
							<el-menu-item index="arrangeInfo">排课信息</el-menu-item>
						<el-menu-item index="addShop">预约排课</el-menu-item>
					</el-submenu>
					<el-submenu index="4">
<template slot="title">
	<i class="el-icon-setting"></i>设置
</template>
						<el-menu-item index="adminList">管理员设置</el-menu-item>
					</el-submenu>
					<el-submenu index="5">
<template slot="title">
	<i class="el-icon-warning"></i>说明
</template>
						<el-menu-item index="explain">说明</el-menu-item>
					</el-submenu>
				</el-menu>
			</el-col>
			<el-col :span="20" style="height: 100%;overflow: auto;">
				<keep-alive>
				    <router-view></router-view>
				</keep-alive>
			</el-col>
		</el-row>
  	</div>
		
</template>

<script>
import { getMessage, readMessage } from "@/api/getData";
import { setInterval, clearInterval } from "timers";
import { Notification } from "element-ui";
export default {
  data() {
    return {
      currentPage: 1
    };
  },
  computed: {
    defaultActive: function() {
      return this.$route.path.replace("/", "");
    }
  },
  mounted() {
    this.getMessageInfo();
    this.poling = setInterval(() => {
      this.getMessageInfo();
    }, 60000);
  },
  watch: {},
  beforeDestroy() {
    clearInterval(this.poling);
  },
  methods: {
    handleClose() {
      this.close();
    },
    async getMessageInfo() {
      const res = await getMessage(this.currentPage);
      if (res.resCode == 0 && !!res.data.data && res.data.data.length > 0) {
        if (!!res.data.data[0] && res.data.data[0].status == 0) {
          this.open();
        }
      }
    },
    open() {
      if (!this.instance) {
        this.instance = this.$notify.info({
          title: "消息",
          message: "有新消息，点击查看",
          duration: 0,
          onClick: () => {
            this.$router.push("message");
            this.$bus.emit("refresh-message", {
              text: "123"
            });
            this.close();
          }
        });
      }
    },
    close() {
      this.instance = undefined;
      Notification.closeAll();
    }
  }
};
</script>


<style lang="less" scoped>
@import "../style/mixin";
</style>
